package SV_IL_SESSION;
import javax.servlet.http.*;
import javax.servlet.*;
import java.math.BigInteger;
import java.security.*;
import java.io.*;
public class Fixed_02 {
    static class Test{
        public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            String id = request.getRequestedSessionId();
            String hashid = getHashValue(id);
            request.getSession().getServletContext().log("Session id: " + hashid);
        }

        public static String getHashValue(String str)
        {
            try {
                MessageDigest md = MessageDigest.getInstance("SHA-256");
                byte[] messageDigest = md.digest(str.getBytes("UTF-8"));
                BigInteger no = new BigInteger(1, messageDigest);
                String hashtext = no.toString(16);
                while (hashtext.length() < 32) {
                    hashtext = "0" + hashtext;
                }
                return hashtext;
            }
            catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    }
}
